package com.woniu.his.bms.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.his.bms.client.InvoiceRecordClient;
import com.woniu.his.bms.client.result.BmsInvoiceResult;
import com.woniu.his.bms.service.InvoiceRecordService;
import com.woniu.his.bms.service.dto.BmsInvoiceDto;
import com.woniu.his.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("bms")
@Slf4j
public class InvoiceRecordApiImpl implements InvoiceRecordClient {

    @Resource
    private InvoiceRecordService invoiceRecordService;


    /**
     * 发票补打
     *
     * @param newInvoiceNo  输入新发票号
     * @param billId 账单id
     * @return
     */
    @Override
    public Result supplementPrintInvoice(Long newInvoiceNo, Long billId) {

        log.info("输入新发票号:{}", newInvoiceNo);
        log.info("账单id:{}",billId);
        boolean b = invoiceRecordService.supplementPrintInvoice(newInvoiceNo, billId);
        return b? Result.getInstance().setMsg("发票补打成功"):Result.getInstance().setMsg("发票补打失败");
    }

    /**
     *  发票重打
     * @param newInvoiceNo 新发票号
     * @param oldInvoiceNo 旧发票号
     * @return
     */
    @Override
    public Result reprintInvoice(Long newInvoiceNo, Long oldInvoiceNo) {
        log.info("输入新发票号{}", newInvoiceNo );
        log.info("输入旧发票号:{}", oldInvoiceNo);
        boolean b = invoiceRecordService.reprintInvoice(newInvoiceNo, oldInvoiceNo);
        return b? Result.getInstance().setMsg("发票重打成功"):Result.getInstance().setMsg("发票重打失败");
    }

    /**
     * 描述：根据新的start_datetime和end_datetime和收费员id，查询发票信息
     */
    @Override
    public Result<List<BmsInvoiceResult>>  queryInvoiceInfo(Long cashierId, Date startDatetime, Date endDatetime) {

        log.info("收费员id:{}", cashierId);
        log.info(" 起止时间:{}", startDatetime);
        log.info("起止时间:{}", endDatetime);
        List<BmsInvoiceDto> list=  invoiceRecordService.queryInvoiceInfo(cashierId,startDatetime,endDatetime);
        List<BmsInvoiceResult> bmsInvoiceResults = BeanUtil.copyToList(list, BmsInvoiceResult.class);
        return Result.getInstanceList(BmsInvoiceResult.class).setData(bmsInvoiceResults).setMsg("查询成功");
    }


    /**
     * 描述：根据日结记录id查询发票
     */
    @Override
    public Result<List<BmsInvoiceResult>> queryInvoiceInfoBySettleId(Long settleRecordId) {
        log.info("结记录id:{}", settleRecordId);
        List<BmsInvoiceDto> list=   invoiceRecordService.queryInvoiceInfoBySettleId(settleRecordId);
        List<BmsInvoiceResult> results = BeanUtil.copyToList(list, BmsInvoiceResult.class);
        return Result.getInstanceList(BmsInvoiceResult.class).setData(results).setMsg("查询成功");
    }





}
